import axios from 'axios'


// const baseURL = import.meta.env.SSR ? 'http://localhost:8080' : 'http://localhost:8080'// 此处和webpack的publicPath保持一致
const baseURL = 'https://www.cirno.asia:8088'

// 创建axios实例
const request = axios.create({
  baseURL: baseURL,
  withCredentials: true,// 跨域访问带上cookie
  timeout: 30000, // 请求超时时间,
})

// 添加request拦截器
request.interceptors.request.use(config => {
  if (config.params) {
    config.params = {
      ...config.params
    }
  }
  if (config.data) {
    config.data = {
      ...config.data
    }
  }
  return config
}, error => {
  Promise.reject(error)
})

// 添加response拦截器
request.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    return Promise.reject(error.response)
  }
)

export default request